<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>我的草稿</title>
    <link rel="stylesheet" href="../../layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layui/css/modules/layer/default/layer.css">
    <link rel="stylesheet" href="../../CSS/media.css">
    <style>
        .layui-card-header {
            font-size: 18px;
        }

        .layui-col-md3 .layui-panel {
            height: 240px;
            box-shadow: 0px 0px 10px 5px #aaa;
            padding: 0px;
            border-radius: 5px;
            background-color: #00F7DE;
        }

        .layui-panel .layui-sys-title {
            height: 40px;
            /*vertical-align:middle;*/
            line-height: 40px;
            width: 100%;
            background-color: #ffffff;
            font-size: 18px;
        }

        .layui-sys-title img {
            /*line-height: 40px;*/
            vertical-align: middle;
            /*float: right;*/
        }

        .draft .layui-tab-title {
            border-bottom-style: none;
            height: 70px;
            line-height: 70px;
            width: 50%;
            display: inline-block;
        }

        .draft .layui-tab-title li {
            font-size: 18px;
            font-weight: bold;
            color: #868686;
            border-right: 2px #9c9c9c solid;
            line-height: 30px !important;
        }

        .draft .layui-tab-title li:last-child {
            border-right: none !important;
        }

        .draft .layui-this {
            color: #1E9FFF !important;
        }

        .draft .layui-this:after {
            border-bottom: 0px !important;
        }

        .s_btn {
            width: 40%;
            float: right;
            position: relative;
            margin-top: 15px;
        }

        .s_btn i {
            font-size: 28px;
            color: #fff;
            position: absolute;
            cursor: pointer;
            background: #1E9FFF;
            text-align: center;
            border-top-right-radius: 5px;
            border-bottom-right-radius: 5px;
            padding: 4px;
        }

        .s_btn input {
            height: 40px;
            background: #f1f1f1;
            border: none;
            font-size: 16px;
            width: 80%;
            display: inline-block;
        }

        .layui-elem-quote {
            background: unset !important;
            font-size: 16px;
            font-weight: bold;
            color: #868686;
            border-left: 5px solid #1E9FFF;
            line-height: 0px;
            margin-left: 10px;
        }

        .layui-col2 {
            height: 260px;
            flex: 0 0 30%;
            padding-right: 10px;
            padding-left: 10px;
            cursor: pointer;
            box-sizing: border-box;
        }

        .layui-col img, .layui-col2 img {
            width: 100%;
            height: 190px;
        }

        .draft {
            width: 100%;
        }

        .draft_title {
            width: 160px;
            margin: auto;
            font-size: 18px;
        }

        .draft_title_b {
            font-weight: bold;
            padding-right: 10px;
        }

        .draft_list {
            display: flex;
            width: 100%;
            flex-wrap: wrap;
            margin-top: 20px;
        }

        .draft_list_imfor {
            width: 100%;
            height: 45px;
            background: #fff;

        }

        .draft_list_imfor_name {
            display: inline-block;
            width: 55%;
            max-width: 190px;
            height: 40px;
            float: left;
            line-height: 40px;
            text-indent: 10px;
            font-weight: bold;
            text-overflow: ellipsis;
            overflow: hidden;
            white-space: nowrap;
        }

        .draft_list_imfor_data {
            display: inline-block;
            width: 45%;
            height: 40px;
            line-height: 40px;
        }

        .draft_list_imfor_data > div {
            float: right;
            margin-right: 10px;
        }

        .layui-col2-card {
            box-shadow: 0 4px 11px 0px #bbbbbb;
            position: relative;
        }

        .add {
            background-image: url(../../static/IMG/Personal/add.png);
            background-repeat: no-repeat;
            background-size: 30%;
            background-position: 50px;
            height: 220px;
        }
        .nav{
            display: none;
            width: 80px;
            height: 125px;
            background: #1E9FFF;
            position: absolute;
            color: #fff;
            text-align: center;
            padding: 8px 0px;
            box-sizing: border-box;
            border-radius: 4px;
        }
        .nav li{
            height: 27px;
            line-height: 27px;
            cursor: pointer;
        }
        .nav li:hover{
            text-decoration: underline;
        }
        .navHandel{
            height: 30px !important;
            width:30px!important;
            position: absolute;
            right:0px;
            bottom: 50px;
        }
    </style>
</head>
<body>
<div class="layui-tab layui-tab-brief draft" lay-filter="draft">
    <ul class="layui-tab-title">
        <li class="layui-this">应用</li>
        <li>模板</li>
        <li>数据</li>
        <li>样式</li>
    </ul>
    <div class="s_btn">
        <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input search">
        <i class="layui-icon ">&#xe615;</i>
    </div>
    <div class="layui-tab-content" style="background-color: #ffffff;">
        <div class="layui-tab-item layui-show app d_item">
            <div class="draft_list">
                <div class="layui-col2 add" onclick="addDataByType('app')"></div>
            </div>
        </div>
        <div class="layui-tab-item mould d_item">
            <div class="draft_list">
                <div class="layui-col2 add" onclick="addDataByType('mould')"></div>
            </div>
        </div>
        <div class="layui-tab-item data d_item">
            <div class="draft_list">
            </div>
        </div>
        <div class="layui-tab-item style d_item">
            <div class="draft_list">
                <div class="layui-col2 add" onclick="addDataByType('style')"></div>
            </div>
        </div>
    </div>
</div>
<!--菜单-->
<ul class="nav">
    <li onclick="draftRel(this)">发布</li>
    <li onclick="copy(this)">复制</li>
    <li onclick="Edit(this)">编辑</li>
    <li onclick="drafDel(this)">删除</li>
</ul>
</body>

<script src="./../../JS/jquery-2.0.3.js"></script>
<script src="../../node_modules/iframeResizer.contentWindow.js"></script>
<script src="../../layui/layui.js" charset="utf-8"></script>
<script src="./../../layui/lay/modules/layer.js"></script>
<script>
    var $view = parent.parent.document.getElementById("view");
    $(function () {
        //点击其他地方菜单栏隐藏
        $(document).click(function (e) {
            if ($('.nav').css('display') !== 'none') {
                e = e || window.event;
                if (e.target.className !== 'navHandel'){
                    $('.nav').hide();
                }
            }
        })
    })
    var tabHandleArr = [0];
    var tabHandle = 0;
    var ajaxUrl = ['/app/selAppByPage','/template/selTemplateByPage','/data/selDataByPage','/style/selStyleByPage'];
    var flow = null;
    var param = {
        'condition': {
            'status': 2,
            'userid': parent.parent.getLocalStorage('JSXM').id,
            'creator': parent.parent.getLocalStorage('JSXM').id
        }
    };
    layui.use(['element', 'layer', 'form','flow'], function () {
        var element = layui.element
        ,layer = layui.layer
        ,form = layui.form;
        flow = layui.flow;
        var type = ['app','mould','data','style'];
        element.on('tab(draft)', function(data){
            tabHandle = data.index;
            if (tabHandleArr.indexOf(data.index) === -1) {
                parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type[tabHandle],0);
                tabHandleArr.push(tabHandle);
            }
        });
        parent.parent.getFlowDataByPost(parent.parent.defaultUrl+'/app/selAppByPage',param,1,flow,getList,'app');
    });

    //编辑
    function Edit(obj) {
        var id = $(obj).parent().attr('key');
        var type = $(obj).parent().attr('type');
        switch (type) {
            case 'app':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Application/appEdit.html?id="+id;
                break;
            case 'mould':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Mould/MouldDetail.html?id="+id;
                break;
            case 'data':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Data/dataEdit.html?id="+id;
                break;
            case 'style':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Style/StyleEdit.html?id="+id;
                break;
        }
        $('.nav').hide();
    }
    
    //删除
    function drafDel(obj) {
        var id = $(obj).parent().attr('key');
        var type = $(obj).parent().attr('type');
        switch (type) {
            case 'app':
                parent.parent.ajaxGet(parent.parent.defaultUrl+'/app/delAppById',{'id':id},function (data) {
                    if (data.code === 200) {
                        layer.msg('删除成功');
                        parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                    } else if (data.message) {
                        layer.msg(data.message)
                    }
                })
                break;
            case 'mould':
                parent.parent.ajaxGet(parent.parent.defaultUrl+'/template/delTemplateById',{'id':id},function (data) {
                    if (data.code === 200) {
                        layer.msg('删除成功');
                        parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                    } else if (data.message) {
                        layer.msg(data.message)
                    }
                })
                break;
            case 'data':
                parent.parent.ajaxGet(parent.parent.defaultUrl+'/data/delDataById',{'id':id},function (data) {
                    if (data.code === 200) {
                        layer.msg('删除成功');
                        parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                    } else if (data.message) {
                        layer.msg(data.message)
                    }
                })
                break;
            case 'style':
                parent.parent.ajaxGet(parent.parent.defaultUrl+'/style/delStyleById',{'id':id},function (data) {
                    if (data.code === 200) {
                        layer.msg('删除成功');
                        parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                    } else if (data.message) {
                        layer.msg(data.message)
                    }
                })
                break;
        }
        $('.nav').hide();
    }
    
    //发布
    function draftRel(obj) {
        parent.parent.sysPopupf('发布设置',parent.parent.$('#fbLevel'),400,360,null,['发布','取消'],function (index,layero) {
            var id = parseInt($(obj).parent().attr('key'));
            var type = $(obj).parent().attr('type');
            //获取该草稿的详细数据
            switch (type) {
                case 'app':
                    parent.parent.ajaxPost(parent.parent.defaultUrl+'/app/insertCheckStatus',{
                        'objid':id || 0,
                        "openness":parent.parent.openness,
                        "openstaff":'',
                        'shuserid':parent.parent.getLocalStorage('JSXM').id,
                        "shstatus": 0
                    },function (data) {
                        if (data.code === 200) {
                            layer.msg('发布成功，等待审核');
                            parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                        } else if (data.message) {
                            layer.msg(data.message)
                        }
                    })
                    break;
                case 'mould':
                    parent.parent.ajaxPost(parent.parent.defaultUrl+'/template/insertCheckStatus',{
                        'objid':id || 0,
                        "openness":parent.parent.openness,
                        "openstaff":'',
                        'shuserid':parent.parent.getLocalStorage('JSXM').id,
                        "shstatus": 0
                    },function (data) {
                        if (data.code === 200) {
                            layer.msg('发布成功，等待审核');
                            parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                        } else if (data.message) {
                            layer.msg(data.message)
                        }
                    })
                    break;
                case 'data':
                    parent.parent.ajaxPost(parent.parent.defaultUrl+'/data/insertCheckStatus',{
                        'objid':id,
                        "openness":parent.parent.openness,
                        // "openstaff":'',
                        // "opengroup":'',
                        'shuserid':parent.parent.getLocalStorage('JSXM').id,
                        "content":"",
                        // "path": path,
                        // "type": type,
                        "status": 0
                    },function (data) {
                        if (data.code === 200) {
                            layer.msg('发布成功，等待审核');
                            parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                        } else if (data.message) {
                            layer.msg(data.message)
                        }
                    })
                    break;
                case 'style':
                    //调用发布接口
                    parent.parent.ajaxPost(parent.parent.defaultUrl+'/style/insertCheckStatus',{
                        'objid':id || 0,
                        "openness":parent.parent.openness,
                        "openstaff":'',
                        'shuserid':parent.parent.getLocalStorage('JSXM').id,
                        "content": "",
                        // "path": path,
                        // "type": type,
                        "status": 0
                    },function (data) {
                        if (data.code === 200) {
                            layer.msg('发布成功，等待审核');
                            parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
                        } else if (data.message) {
                            layer.msg(data.message)
                        }
                    })
                    break;
            }
            $('.nav').hide();
            parent.parent.layer.close(index)
        })
    }

    //复制
    function copy(obj) {
        var id = parseInt($(obj).parent().attr('key'));
        var type = $(obj).parent().attr('type');
        var copyUrl = ['/app/copy','/template/copy','/data/copy','/style/copy'];
        parent.parent.ajaxGet(parent.parent.defaultUrl+copyUrl[tabHandle],{'id':id},function (data) {
            if (data.code === 200) {
                layer.msg('复制成功');
                parent.parent.getFlowDataByPost(parent.parent.defaultUrl+ajaxUrl[tabHandle],param,1,flow,getList,type,1);
            } else if (data.message) {
                layer.msg(data.message)
            }
        })
    }

    //编辑按钮
    function showNav(obj,id,type) {
        var left = $(obj).offset().left - 80;
        var top = $(obj).offset().top - 95;
        $('.nav').show().css({'left':left,'top':top}).attr({'key':id,'type':type});
    }

    //新增个模块的应用
    function addDataByType(type) {
        switch (type) {
            case 'app':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Application/appEdit.html";
                break;
            case 'mould':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Mould/MouldDetail.html";
                break;
            case 'data':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Data/dataEdit.html";
                break;
            case 'style':
                $view.style.marginTop = '0px';
                $view.src = "HTML/Style/styleEdit.html";
                break;
        }
    }

    //页面生成html
    function getList(data,type,type2) {
        if (type2) {
            $('.'+type).find('.draft_list').html('');
        }
        var html = ''
        for (var i = 0,l=data.length;i<l;i++) {
            var img = data[i].img || '../../static/IMG/nothumb.png';
            html+='                    <div class="layui-col2" key="'+data[i].id+'" type="'+data[i].type+'">\n' +
                '                        <div class="layui-col2-card">\n' +
                '                            <img src="'+img+'">\n' +
                '                            <img class="navHandel" src="../../static/IMG/Common/editor.png" onclick="showNav(this,\''+data[i].id+'\',\''+type+'\');" />\n' +
                '                            <div class="draft_list_imfor">\n' +
                '                                <div class="draft_list_imfor_name">'+data[i].name+'</div>\n' +
                '                                <div class="draft_list_imfor_data">\n' +
                '                                    <div>\n' +
                '                                        '+data[i].time.split(' ')[0]+'' +
                '                                    </div>\n' +
                '                                </div>\n' +
                '                            </div>\n' +
                '                        </div>\n' +
                '                    </div>';
        }
        if (type !== 'data') {
            html+='<div class="layui-col2 add" onclick="addDataByType(\''+type+'\')"></div>';
        }
        html += '</div>';
         //判断类型
        if (type !== 'data') {
            $('.'+type).find('.draft_list').find('.add').remove();
        }
        $('.'+type).find('.draft_list').append(html);
    }

</script>
</html>